<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书-用户借阅</title>
    <link rel="icon" href="/static/images/t_logo.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/lyk-global.css" />
    <link rel="stylesheet" href="/static/elementui/lib/theme-chalk/index.css">
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script src="/static/js/requestApi.js" type="text/javascript"></script>
    <script src="/static/js/vue/vue.js"></script>
    <!-- 引入elementui -->
    <script src="/static/elementui/js/element.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/axios-config.js"></script>
    <script src="/static/js/utilJs.js"></script>
</head>
<style>
    [v-cloak] {
        display: none;
    }
</style>
<body style="background-color: #fff">
<div id="app" v-cloak>
    <div class="mt-8 ml-4">

        <div class="mt-9">
            <h3>借阅信息</h3>
            <div class="df">
                <el-input placeholder="请输入条形码" size="small" style="width:200px;" v-model="ticketNumber" ></el-input>
                <el-button size="small" type="primary" @click="searchBookStock" class="ml-2">搜索</el-button>
                <el-button size="small" type="primary" @click="borrowBookMethod" class="ml-2">完成借阅</el-button>
            </div>

            <el-table :data="borrowBookTableData">
                <el-table-column prop="bookName" label="书籍名称"></el-table-column>
                <el-table-column prop="isbn" label="isbn"></el-table-column>
                <el-table-column prop="indexBookNumber" label="索书号"></el-table-column>
                <el-table-column prop="shelfMark" label="排架号"></el-table-column>
                <el-table-column prop="ticketNumber" label="条形码"></el-table-column>
                <el-table-column prop="picUrl" label="图片">
                    <template slot-scope="scope">
                        <img  :src="'/book/getLocalSystemPic?filePath=' + scope.row.picUrl" width="42" height="42">
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <el-button type="danger" size="small" @click="removeBorrow(scope.row,scope.$index)">移除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>

</div>
</body>

<script type="text/javascript">
    const vm = new Vue({ // 配置对象 options
        // 配置选项(option)
        el: '#app', // element: 指定用vue来管理页面中的哪个标签区域
        components: {
        },
        data() {
            return {
                ticketNumber : "",
                borrowBookTableData:[],
                queryParam : {
                    name:"",
                    idCard:""
                },
                tableData : [],
            }
        },
        mounted() {
            this.$nextTick(function () {

            });
        },
        methods: {


            //查询库存信息
            searchBookStock(){
                let that = this;
                if(!that.ticketNumber){
                    that.$message.error("请填写条码号");
                    return;
                };
                //that.borrowBookTableData = [];
                requestApiTB("book/stock/getBookStockByTicketNumber",{"ticketNumber" : that.ticketNumber},'post',function(res){
                    if(res.code === 0){
                        if(res.data){
                            if(res.data.status === '3'){
                                that.$message.error("该书籍已经外借了");
                            }else{
                                that.borrowBookTableData.push(res.data);
                            }
                        }else{
                            that.$message.error("查找不到数据");
                        }
                    }else{
                        that.$message.error(res.msg);
                    }
                });
            },

            //借阅的方法
            borrowBookMethod(){
                let that = this;
                if(that.borrowBookTableData.length == 0){
                    that.$message.error("请选择需要借阅的书籍");
                    return;
                }
                let deepCopyborrowBookTableData = JSON.parse(JSON.stringify(that.borrowBookTableData));
                for(let i = 0 ; i < deepCopyborrowBookTableData.length; i++ ){
                    deepCopyborrowBookTableData[i].bookStockId = deepCopyborrowBookTableData[i].id;
                }
                let submitData = {
                    "borrowBooks" : deepCopyborrowBookTableData
                }
                //判断书籍的状态
                requestApiTB("record/borrowBookYh",submitData,"post",function(res){
                    if (res.code === 0) {
                        if(res.data){
                            that.$message.success("操作成功");
                            setTimeout(function(){
                                location.reload();
                            }, 2000);
                        }
                    }else{
                        that.$message.error(res.msg);
                    }
                })
            },

            removeBorrow(row,index){
                let that = this;
                that.borrowBookTableData.splice(index, 1);
            },




        }
    })
</script>
</html>